package com.zhixinhuixue.zsyte.xxx.data.repository

import com.zhixinhuixue.zsyte.xxx.app.App
import com.zhixinhuixue.zsyte.xxx.app.api.NetUrl
import com.zhixinhuixue.zsyte.xxx.data.annotation.ValueKey
import com.zhixinhuixue.zsyte.xxx.data.response.*
import me.hgj.mvvmhelper.util.SPUtil
import rxhttp.IAwait
import rxhttp.wrapper.param.RxHttp
import rxhttp.wrapper.param.toResponse

/**
 * 作者　: hegaojian
 * 时间　: 2020/11/2
 * 描述　: 数据仓库
 */
object UserRepository {

    /**
     * 登录
     */
    fun login(userName: String, password: String): IAwait<String> {

        return RxHttp.postJson(( SPUtil.get(App.instance, ValueKey.HOST_KEY, NetUrl.DEV_URL) as String)+NetUrl.LOGIN)
            .add("account", userName)
            .add("password", password)
            .toResponse()
    }

    /**
     * 修改密码
     */
    fun password(userName: String, password: String): IAwait<List<MainEntity>> {
        return RxHttp.postJson(SPUtil.get(App.instance, ValueKey.HOST_KEY, NetUrl.DEV_URL) as String+NetUrl.PASSWORD)
            .add("Password", userName)
            .add("NewPassword", password)
            .toResponse()
    }

    /**
     * 物料上架
     */
    fun wlsj(customer_id: String, StorageRacks_Code: String, Code: String, Type: String): IAwait<String> {
        return RxHttp.postJson(SPUtil.get(App.instance, ValueKey.HOST_KEY, NetUrl.DEV_URL) as String+NetUrl.WULIAOSHANGJIA)
            .add("customer_id", customer_id)
            .add("package_no", StorageRacks_Code)
            .add("package_sn", Code)
            .add("package_type", Type)
            .toResponse()
    }

    /**
     * 获取所有领用单
     */
    fun getStoresRequisitionSheet(): IAwait<List<StoresRequisitionSheet>> {
        return RxHttp.get(SPUtil.get(App.instance, ValueKey.HOST_KEY, NetUrl.DEV_URL) as String+NetUrl.GET_STORESREQUISITIONSHEET)
            .toResponse()
    }

    /**
     * 获取物料名称
     */
    fun getStoresRequisitionSheetById(StoresRequisitionSheet_Id: String): IAwait<List<StoresRequisitionSheetItem>> {
        return RxHttp.get(SPUtil.get(App.instance, ValueKey.HOST_KEY, NetUrl.DEV_URL) as String+NetUrl.GET_STORESREQUISITIONSHEET_ITEM)
            .add("StoresRequisitionSheet_Id", StoresRequisitionSheet_Id)
            .toResponse()
    }

    /**
     * 物料出库
     * */
    fun Picking(StoresRequisitionSheet_Id: String, Material_Id: String, DeliveryLabelsItems: List<String>): IAwait<Any> {
        return RxHttp.postJson(SPUtil.get(App.instance, ValueKey.HOST_KEY, NetUrl.DEV_URL) as String+NetUrl.Picking)
            .add("StoresRequisitionSheet_Id", StoresRequisitionSheet_Id)
            .add("Material_Id", Material_Id)
            .add("DeliveryLabelsItems", DeliveryLabelsItems)
            .toResponse()
    }

    /**
     * SMT上料
     * */
    fun addPicking(WorkOrdersSheet_Id: String, Feeder_Id: String, MaterialShelves_Id: String, StationTable_Id: String): IAwait<Any> {
        return RxHttp.postJson(SPUtil.get(App.instance, ValueKey.HOST_KEY, NetUrl.DEV_URL) as String+NetUrl.Feeding_Add)
            .add("WorkOrdersSheet_Id", WorkOrdersSheet_Id)
            .add("Feeder_Code", Feeder_Id)
            .add("MaterialShelves_Code", MaterialShelves_Id)
            .add("StationTable_Code", StationTable_Id)
            .toResponse()
    }

    /**
     * SMT核料
     * */
    fun checkPicking(WorkOrdersSheet_Id: String, Feeder_Id: String, MaterialShelves_Id: String, StationTable_Id: String): IAwait<Any> {
        return RxHttp.postJson(SPUtil.get(App.instance, ValueKey.HOST_KEY, NetUrl.DEV_URL) as String+NetUrl.Feeding_Check)
            .add("WorkOrdersSheet_Id", WorkOrdersSheet_Id)
            .add("Feeder_Code", Feeder_Id)
            .add("MaterialShelves_Code", MaterialShelves_Id)
            .add("StationTable_Code", StationTable_Id)
            .toResponse()
    }


    /**
     * 根据架位号查询架位所有物料
     */
    fun getMaterialShelves(StorageRacks_Code: String): IAwait<List<MaterialShelvesEntity>> {
        return RxHttp.get(SPUtil.get(App.instance, ValueKey.HOST_KEY, NetUrl.DEV_URL) as String+NetUrl.GET_MATERIALSHELVES)
            .add("StorageRacks_Code", StorageRacks_Code)
            .toResponse()
    }

    /**
     * 获取工单
     */
    fun getWorkOrdersSheet(): IAwait<List<MaterialShelvesEntity>> {
        return RxHttp.get(SPUtil.get(App.instance, ValueKey.HOST_KEY, NetUrl.DEV_URL) as String+NetUrl.GET_WORKORDERSSHEET)
            .add("Flag", 4)
            .toResponse()
    }


    /**
     * 获取列表信息
     */
    fun getList(pageIndex: Int): IAwait<ApiPagerResponse<Any>> {
        return RxHttp.get(SPUtil.get(App.instance, ValueKey.HOST_KEY, NetUrl.DEV_URL) as String+NetUrl.HOME_LIST, pageIndex)
            .toResponse()
    }

    /**
     * 获取列表信息
     */
    fun getFunList(): IAwait<MutableList<MainEntity>> {
        return RxHttp.get(SPUtil.get(App.instance, ValueKey.HOST_KEY, NetUrl.DEV_URL) as String+NetUrl.HOME_LIST)
            .toResponse()
    }

    /**
     * 获取列表信息
     */
    fun getBannerList(): IAwait<List<MainEntity>> {
        return RxHttp.get(SPUtil.get(App.instance, ValueKey.HOST_KEY, NetUrl.DEV_URL) as String+NetUrl.HOME_BANNER)
            .toResponse()
    }



}

